/*
 * @Author: your name
 * @Date: 2021-12-24 17:52:31
 * @LastEditTime: 2021-12-25 02:02:50
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \json-serveg:\桌面2\50htmljs\counter\script.js
 */
const counters = document.querySelectorAll('.counter')
// const b = document.getElementsByClassName('counter')

counters.forEach((counter)=>{
    // console.log(counter)
    //获取标签内的默认计数器的值
         const target = counter.getAttribute('data-target')
        // console.log(target)
       
        let i = 0 

        const timer = setInterval(()=>{
            const num = parseInt(target / 50)
            i += num 
            counter.innerText = i
            if ( i >= Number(target)) {
                clearInterval(timer)
                counter.innerText = target
            }

        },17)



    // //定义计数器为0
    // counter.innerText = 0

    // //更新计数器
    // const upadteCounter =()=>{
    //     //获取标签内的默认计数器的值
    //     const target = counter.getAttribute('data-target')
    //     return console.log(target)



    // }



})









